<?php $this->load->view('includes/project_view_header'); ?>

<script>
	$(document).ready(function(){
		loadCommentsList();		
	});

	function loadCommentsList(){
		$.ajax({
			url: CI.baseUrl + '/index.php/tasks_controller/get_task_comments_json',
			type: 'POST',
			data: {'task_id': '<?= $id ?>'},
			dataType: "json",
			success: function(data){
				loadCommentsListCallback(data);
			},
			error: function(data){
				alert('error');
			}
		});
	}
	
	function loadCommentsListCallback(data){
		var container;
		var headerContainer;
		var headerContent;
		var commentContainer;
		for(var i=0; i<data.length; i++){
			comment = $(document.createElement("div"));
			
			header 	= $(document.createElement("div"))
				.attr({class: 'grid_12 ui-widget-header'});

			headerContent = $(document.createElement("b"))
				.text("Created by " + data[i].first_name + " " + data[i].last_name + " on " + data[i].created_date);
			
			content = $(document.createElement("div"))
				.attr({class: 'grid_12'})
				.text(data[i].comment);

			comment.appendTo("#comments-list");
			comment.append(header);
			header.append(headerContent);
			comment.append(content);
		} 
	}
</script>

<style>
	label{
		display: block;
		font-weight: bold;
	}
</style>

<div id="content" class="container_12" title="Task information">
	<div class="grid_12">
		<p>
			<label for="subject">Subject</label>
			<span name="subject" id="subject"><?= $subject ?></span>
		</p>
	</div>
	<div class="clear"></div>
	<div class="grid_12">
		<p>
			<label for="description">Description</label>
			<span id="description" name="description" id="description"><?= $description ?></span>
		</p>
	</div>
	<div class="clear"></div>
	<div class="grid_6">
		<p>
			<label for="priority">Priority</label>
			<span id="priority" name="priority"><?= $priority ?></span>
		</p>
	</div>
	<div class="grid_6">
		<p>
			<label for="status">Status</label>
			<span id="status" name="status"><?= $status ?></span>
		</p>
	</div>
	<div class="clear"></div>
	<div class="grid_6">
		<p>
			<label for="completed">% completed</label>
			<span id="completed" name="completed"><?= $percentaje_completed ?></span>
		</p>
	</div>
	<div class="grid_6">
		<p>
			<label for="estimated_hours">Estimated Hours</label>
			<span id="estimated_hours" name="estimated_hours"><?= $estimated_hours ?></span>
		</p>
	</div>
	<div class="clear"></div>
	<div class="grid_6">
		<p>
			<label for="worked_hours">Worked Hours</label>
			<span id="worked_hours" name="worked_hours"><?= $worked_hours ?></span>
		</p>
	</div>
	<div class="grid_6">
		<p>
			<label for="assigned_to">Assigned to</label>
			<span id="assigned_to" name="assigned_to"><?= $assigned_to ?></span>
		</p>
	</div>
	<div class="clear"></div>
	<div class="grid_6">
		<p>
			<label for="sprint">Sprint</label>
			<span id="sprint" name="sprint"><?= $sprint ?></span>
		</p>
	</div>
	<div class="clear"></div>
</div>

<div id="comments" class="container_12">
	<div>
		<form id="new-comment-form" METHOD="POST" action="<?= base_url() ?>index.php/tasks_controller/save_comment">
			<div class="grid_12">
				<label for="new-comment">New comment</label>
				<textarea name="comment" id="comment" rows="10" style="width:100%"></textarea>
				<input type="hidden" id="ref_id" name="ref_id" value="<?= $id ?>"/>
				<input type="submit" id="save-comment" name="save-comment" value="Create comment"/>
			</div>
			<div class="clear"></div>
		</form>
	</div>
	<div id="comments-list">
	</div>
</div>
<?php $this->load->view('includes/footer'); ?>